.category-list {
  table-layout: fixed;

  tbody {
    .category {
      &.no-category-style {
        border-color: transparent;
        border-left: 0;
        padding-left: 0;
      }
    }
  }

  .category-text-title {
    display: flex;
    align-items: baseline;
  }

  .category-name {
    display: inline-block;
    max-width: 100%;

    @include ellipsis;
    vertical-align: text-top;
    line-height: var(--line-height-medium);
  }

  &.with-topics {
    .subcategories-with-subcategories {
      .category-description {
        display: none;
      }
    }
  }

  &.hidden {
    display: none;
  }
}

.navigation-categories .category-list.subcategory-list {
  margin-bottom: 1em;
}

.subcategory-list {
  .parent-category {
    h3 {
      display: inline;
    }

    .category-text-title {
      display: inline-flex;
    }

    .stat {
      margin-left: 0.5em;
    }
  }
}

.category-boxes,
.category-boxes-with-topics {
  display: grid;
  gap: 1.5em;
  margin-top: 1em;
  margin-bottom: 1em;
  width: 100%;

  .category-box {
    position: relative;
    display: flex;
    flex-direction: row;
    align-content: flex-start;
    box-sizing: border-box;
    border-width: 0;
    border-left-width: 6px;
    border-style: solid;
    border-color: var(--category-badge-color, var(--primary-low));

    .mobile-view & {
      width: 100%;
    }

    h3 .d-icon {
      margin-right: 0;
    }

    .parent-box-link {
      // This avoids an issue with nested links by layering links instead
      &::before {
        content: "";
        position: absolute;
        z-index: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
      }
    }

    .category-logo.aspect-image img {
      display: block;
      width: auto;
      height: 40px;
      margin: 0 auto 1em auto;
    }

    @supports (--custom: property) {
      .category-logo.aspect-image img {
        --height: 40px;
        height: var(--height);
        width: calc(var(--height) * var(--aspect-ratio));
        max-width: 100%;
      }
    }
  }

  .category-box-inner {
    box-sizing: border-box;
    width: 100%;
    padding: 1em;
    display: flex;
    flex-direction: column;
    border-width: 2px;
    border-left-width: 0;
    border-style: solid;
    border-color: var(--primary-low);
  }

  &.no-logos {
    .category-logo {
      display: none;
    }
  }

  .badge-category__wrapper {
    max-width: 100%;
  }
}

.category-boxes {
  grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));

  .category-box {
    > a {
      width: 100%;
      padding: 0;
    }

    .category-box-inner {
      padding: 1em;

      .category-logo {
        float: none;
        margin: 0;
      }
    }
  }

  &.no-logos {
    .category-box .category-box-inner > a {
      padding: 3em 1em;
    }
  }

  .description {
    margin-bottom: 1em;
    text-align: center;
    font-size: var(--font-0);
    color: var(--primary-med-or-secondary-high);
    position: relative;

    @include line-clamp(4);

    //  allow clicks to fall through the description text to the category below...
    pointer-events: none;

    .overflow {
      max-height: 6em;

      div a {
        //  ...but links in description should still be clickable
        pointer-events: auto;
      }
    }
  }

  h3 {
    font-size: var(--font-up-2);
    margin-bottom: 0.5em;
    margin-top: 0.25em;
    line-height: var(--line-height-medium);
    text-align: center;
    color: var(--primary);
    overflow: hidden;
  }

  h4 a {
    color: var(--primary);
  }

  .subcategory.with-subcategories {
    position: relative;
    border: none;
    border-left-width: 4px;
    border-left-style: solid;
    margin-bottom: 0.25em;

    .category-title-link {
      display: flex;

      .category-logo {
        flex: 1 0 auto;
        margin: 0.25em 0.5em 0.5em 0;

        --max-height: 40px;
      }

      .category-text-title {
        order: 2;
        line-height: var(--line-height-medium);
        overflow: hidden;
        margin-bottom: 0.25em;
        word-wrap: break-word;
      }

      &::before {
        // This avoids an issue with nested links by layering links instead
        content: "";
        position: absolute;
        z-index: 0;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
      }
    }

    .subcategory-box-inner {
      border: 1px solid var(--primary-low);
      border-left: none;
      padding: 0.5em 0.5em 0.4em 0.5em;
    }

    &:not(:last-of-type) {
      margin-bottom: 0.75em;
    }

    .subcategory {
      margin-bottom: 0.25em;
    }
  }

  .subcategories {
    display: flex;
    flex-flow: wrap;

    .subcategory {
      display: flex;
      align-items: center;

      @include ellipsis;
      margin-bottom: 0.6em;

      .badge-category__wrapper {
        overflow: hidden;
      }

      .subcategory-image-placeholder {
        display: inline-block;
        margin-right: 0.6em;
        flex: 1 0 auto;
      }

      .subcategory-link {
        min-width: 0;

        @include ellipsis;
      }

      .category-logo img {
        display: inline-block;

        --height: 20px;
        height: var(--height);
        width: calc(var(--height) * var(--aspect-ratio));
        margin: 0;
      }
    }
  }
}

.category-boxes-with-topics {
  grid-template-columns: repeat(auto-fit, minmax(18em, 1fr));

  .category-box {
    padding: 0;
  }

  h3 {
    font-size: var(--font-up-2);
    text-align: center;
    overflow: hidden;
  }

  .category-box-heading {
    margin-bottom: 0.5em;

    a[href] {
      width: 100%;
      color: var(--primary);
    }
  }

  .featured-topics {
    margin-bottom: 1em;

    // we absolutely position the parent category's link so the whole box is clickable
    // to prevent this covering topic links, we need to raise the z-index
    z-index: 1;

    ul {
      color: var(--primary-medium);
      list-style: none;
      padding: 0;
      margin: 0;
    }

    li {
      padding: 4px 0;
      display: flex;
      align-items: baseline;

      a {
        @include line-clamp(2);
      }

      .d-icon {
        margin-right: 0.15em;
        width: 0.76em;
        height: 0.76em;
      }
    }
  }
}

.categories-list .category {
  h3,
  h4 {
    margin-bottom: 0;
  }

  .category-description {
    margin-top: 0.5em;
    overflow: hidden;
    color: var(--primary-high);
  }

  .category-logo.aspect-image {
    margin-top: 0.5em;
  }
}

.category-list.subcategories-with-subcategories {
  margin-top: 1em;
  margin-bottom: 0;
  border-top: 1px solid var(--primary-low);

  .category-description {
    font-size: var(--font-down-1);
  }

  .category-logo.aspect-image {
    --max-height: 75px;
  }
}

.category-list .category.muted {
  > h3 a.category-title-link,
  > h4 a.category-title-link {
    color: var(--primary-medium);
    font-size: var(--font-down-1);
  }

  > .category-description,
  tr.category-description {
    display: none;
  }
}

.category-box.no-category-boxes-style {
  border-left-width: 2px;
}

.muted-categories-link {
  border: 1px solid var(--primary-low);
  display: flex;
  justify-content: space-between;
  padding: 0.75em;
  border-left-width: 6px;
  border-right: none 0;
  margin-left: -3px;

  .d-icon {
    color: var(--primary-medium);
    margin-top: 0.25em;
  }
}

.muted-categories-heading {
  color: var(--primary-medium);
  margin: 0;
}

.anon .muted-categories-link {
  display: none;
}

.navigation-categories .category-list {
  margin-bottom: 3em;

  .category-list {
    margin-bottom: 0;
  }
}
